package day11.CRUD;

import com.mysql.jdbc.CallableStatement;
import com.mysql.jdbc.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class Demo5 {

    /*
     *jdbc调用存储过程

 create procedure p_course_insert
@c_no nvarchar(50),
@c_name nvarchar(50),
@t_name nvarchar(50)
as
insert into t_course(c_no,c_name,t_name)
values(@c_no,@c_name,@t_name)
     */
    public static void main(String[] args) {


        Connection conn = null;
        CallableStatement cs = null;
        ResultSet rs = null;

        try{
            conn = JdbcUtils.getConnection();
            cs = (CallableStatement) conn.prepareCall("{call p_course_inser(?,?,?)}");
            cs.setString(1, "xxxxx");
            cs.registerOutParameter(2, Types.VARCHAR);

            cs.execute();
            String result = cs.getString(2);
            System.out.println(result);

        }catch (Exception e) {
            e.printStackTrace();
        }finally{
            JdbcUtils.release(conn, cs, rs);
        }

    }
}